<?php
class UserTournamentsController extends AppController {

	var $name = 'UserTournaments';
	var $helpers = array('Html', 'Form');

	function index($tournamentId = null) {
		$this->UserTournament->recursive = 0;
		if(is_null($tournamentId))
			$this->set('userTournaments', $this->paginate());
		else{
			$this->set('userTournaments', $this->paginate('UserTournament', array('UserTournament.tournament_id' => $tournamentId)));
			/*$this->UserTournament->find('all', array(
															'conditions' => array('UserTournament.tournament_id' => $tournamentId), //array of conditions
															//'recursive' => -1, //int
															//'fields' => array('Model.field1', 'Model.field2'), //array of field names
															//'order' => array('Model.created', 'Model.field3 DESC'), //string or array defining order
															//'group' => array('Model.field'), //fields to GROUP BY
															//'limit' => n, //int
															//'page' => n, //int
															//'callbacks' => true //other possible values are false, 'before', 'after'
														));*/
			$this->set('tournament', $this->UserTournament->Tournament->find('first', array(
															'conditions' => array('Tournament.id' => $tournamentId), //array of conditions
															'recursive' => -1, //int
															//'fields' => array('Model.field1', 'Model.field2'), //array of field names
															//'order' => array('Model.created', 'Model.field3 DESC'), //string or array defining order
															//'group' => array('Model.field'), //fields to GROUP BY
															//'limit' => n, //int
															//'page' => n, //int
															//'callbacks' => true //other possible values are false, 'before', 'after'
														)));
		}
	}

	function view($id = null) {
		if (!$id) {
			$this->flash(__('Invalid UserTournament', true), array('action'=>'index'));
		}
		$this->set('userTournament', $this->UserTournament->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->UserTournament->create();
			if ($this->UserTournament->save($this->data)) {
				$this->flash(__('UserTournament saved.', true), array('action'=>'index'));
			} else {
			}
		}
		$users = $this->UserTournament->User->find('list');
		$tournaments = $this->UserTournament->Tournament->find('list');
		$tournamentgroups = $this->UserTournament->Tournamentgroup->find('list');
		$deposits = $this->UserTournament->Deposit->find('list');
		$this->set(compact('users', 'tournaments', 'tournamentgroups', 'deposits'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->flash(__('Invalid UserTournament', true), array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->UserTournament->save($this->data)) {
				$this->flash(__('The UserTournament has been saved.', true), array('action'=>'index'));
			} else {
			}
		}
		if (empty($this->data)) {
			$this->data = $this->UserTournament->read(null, $id);
		}
		$users = $this->UserTournament->User->find('list');
		$tournaments = $this->UserTournament->Tournament->find('list');
		$tournamentgroups = $this->UserTournament->Tournamentgroup->find('list');
		$deposits = $this->UserTournament->Deposit->find('list');
		$this->set(compact('users','tournaments','tournamentgroups','deposits'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->flash(__('Invalid UserTournament', true), array('action'=>'index'));
		}
		if ($this->UserTournament->del($id)) {
			$this->flash(__('UserTournament deleted', true), array('action'=>'index'));
		}
	}

}
?>